﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Threading;

namespace 第十次课程作业
{
    public partial class Form1 : Form
    {
        private delegate void MyDelegate();
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {

                Thread thread1 = new Thread(new ThreadStart(BaiduSearch));
                Thread thread2 = new Thread(new ThreadStart(BingSearch));
                thread1.Start();
                thread2.Start();

            }
            catch (Exception )
            {
                MessageBox.Show("未知错误");
            }
        }
        private void BaiduSearch()
        {
            String url = "https://www.baidu.com/baidu/s?wd=" + textBox1.Text;
            WebClient webClient = new WebClient();
            byte[] recvdata = webClient.DownloadData(url);
            string response = Encoding.UTF8.GetString(recvdata);
            this.BeginInvoke(new MyDelegate(() => { richTextBox1.Text = response.Substring(0, 100); }));
        }

        private void BingSearch()
        {
            String url = "https://cn.bing.com/search?q=" + textBox1.Text;
            WebClient webClient = new WebClient();
            byte[] recvdata = webClient.DownloadData(url);
            string response = Encoding.UTF8.GetString(recvdata);
            this.BeginInvoke(new MyDelegate(() => { richTextBox2.Text = response.Substring(0, 100); }));
        }
       
        

       
    }
}
